import request from '@/utils/request'

// api/comment.js

// 获取评论列表方法
export const getComments = ({ workId, page = 1, pageSize = 5 }) => {
    return request({
      url: `/api/work/${workId}/comments`, // 路径参数中包含 workId
      method: 'get',
      params: {
        workId,  // 同时作为查询参数传递
        page,
        pageSize
      }
    })
  }
  
 

// 提交评论方法
export const submitComment = (params) => {
  const workId = params.workId; // 从 params 中获取 workId
  return request({
    url: `/api/work/${workId}/comments`,
    method: 'post',
    data: {
      userId: params.userId,
      workId: workId,  // 使用固定的 workId
      superiorId: params.superiorId,
      respondentId: params.respondentId,
      content: params.content
    }
  })
}

// 提交回复方法
export const submitReply = (params) => {
  const workId = params.workId; // 从 params 中获取 workId
  return request({
    url: `/api/work/${workId}/comments`,
    method: 'post',
    data: {
      userId: params.userId,
      workId: workId,  // 使用固定的 workId
      superiorId: params.superiorId,
      respondentId: params.respondentId,
      content: params.content
    }
  })
}

  
  // 添加获取回复列表方法
  export const getReplies = (workId, commentId) => {
    return request({
      url: `/api/work/${workId}/comments/${commentId}/replies`,
      method: 'get'
    })
  }
  
  // 删除评论方法
  export const deleteComment = (commentId) => {
    return request({
      url: `/api/comments/${commentId}`,
      method: 'delete'
    })
  }
  


// 上传附件
// export const uploadAttachment = (workId, file) => {
//   const formData = new FormData()
//   formData.append('file', file)
//   return request({
//     url: `/api/work/${workId}/comment/attachment`,
//     method: 'post',
//     data: formData,
//     headers: {
//       'Content-Type': 'multipart/form-data'
//     }
//   })
// }
